// Copyright (c) 2006, Gregory Todd <greg@oddsim.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
// 
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Othello.WinOthello
{
    public delegate void SelectHandler(object sender, SelectArgs e);
    public partial class SpaceButton : UserControl
    {
        public event SelectHandler SelectEvent;

        public Image Image
        {
            get { return pictureBox1.Image; }
            set { pictureBox1.Image = value; }
        }

        private int _x;
        public int X
        {
            get { return _x; }
            set { _x = value; }
        }

        private int _y;
        public int Y
        {
            get { return _y; }
            set { _y = value; }
        }

        bool _isBlank;
        bool _isDark;
        bool _isLight;

        public bool isBlank()
        {
            return _isBlank;
        }
        public bool isDark()
        {
            return _isDark;
        }
        public bool isLight()
        {
            return _isLight;
        }

        public void setBlank()
        {
            _isBlank = true;
            _isDark = false;
            _isLight = false;
        }
        public void setDark()
        {
            _isBlank = false;
            _isDark = true;
            _isLight = false;
        }
        public void setLight()
        {
            _isBlank = false;
            _isDark = false;
            _isLight = true;
        }

        public SpaceButton(int x, int y)
        {
            InitializeComponent();
            setBlank();
            _x = x;
            _y = y;
            toolTip1.SetToolTip(pictureBox1, String.Format("{0}, {1}", _x + 1, _y + 1));
        }

        private void OnSelectEvent()
        {
            if (SelectEvent != null)
                SelectEvent(this, new SelectArgs(X, Y));
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            OnSelectEvent();
        }
    }
    public class SelectArgs : EventArgs
    {
        private int _x;
        public int X
        {
            get { return _x; }
        }

        private int _y;
        public int Y
        {
            get { return _y; }
        }

        public SelectArgs(int x, int y)
        {
            _x = x;
            _y = y;
        }	
    }
}
